package com.yitiao.controller;

import com.yitiao.disruptor.DisruptorMqService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/disruptor")
@RequiredArgsConstructor
@Slf4j
public class DisruptorController {

    private final DisruptorMqService disruptorMqService;

    @GetMapping("/send")
    @SneakyThrows
    public void sendOrder(@RequestParam(defaultValue = "hello") String message) {
        disruptorMqService.createOrderToMq(message);
        log.info("消息队列已发送完毕");
        //这里停止2000ms是为了确定是处理消息是异步的
        Thread.sleep(2000);
    }

    @GetMapping("/send/count")
    @SneakyThrows
    public void sendOrderCount(Integer count) {
        for (int i = 0; i < count; i++) {
            disruptorMqService.createOrderToMq("count:"+i);
            log.info("消息队列已发送完毕:"+i);
            //这里停止2000ms是为了确定是处理消息是异步的
//            Thread.sleep(2000);
        }
    }
}
